import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:mybase/base/tool/globalMethod/FFScreenValue.dart';
import 'package:mybase/base/tool/platformUtils/FFPlatform.dart';

// 进入横屏
// await DeviceDirection.landscapeByOrien([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
// DeviceStatus.hidden();
// 跳转页面代码

// 从横屏退出到竖屏
// await DeviceDirection.portrait();
// DeviceStatus.show();
// 跳转页面代码

class DeviceDirection {
  ///横屏
  static Future<void> landscape() async {
    await SystemChrome.setPreferredOrientations(
        [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
  }

  ///指定方向
  static Future<void> landscapeByOrien(List<DeviceOrientation> list) async {
    await SystemChrome.setPreferredOrientations(list);
  }

  ///竖屏
  static Future<void> portrait() async {
    await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  }

  ///切换屏幕方向
  static Future<void> switchOrientation(BuildContext context) async {
    Orientation currentOrientation = await getOrientation(context);
    if (currentOrientation == Orientation.portrait) {
      await landscape();
    } else {
      await portrait();
    }
  }

  ///获取屏幕的方向
  static Orientation getOrientation(BuildContext context) {
    Orientation currentOrientation = MediaQuery.of(context).orientation;
    return currentOrientation;
  }

  ///获取屏幕宽高比，Android端在横屏和竖屏时，宽高比不一样的，iOS一样
  static Size getLandscapeRealSize(BuildContext context,
      {bool? isLandcape = false}) {
    if (isLandcape == true) {
      ///横屏时
      return Size(globalScreenWidth(context), globalScreenHeight(context));
    }

    ///竖屏时
    if (FFPlatform.isAndroid) {
      return Size(globalScreenWidth(context),
          globalScreenHeight(context) - globalScreenPaddingTop(context));
    } else {
      return Size(globalScreenWidth(context), globalScreenHeight(context));
    }
  }
}
